package com.wanghlme.leetcodecn;

/**
 * <p>剑指 Offer 05. 替换空格</p>
 *
 * @author wanghlme
 * @version 1.0
 */
public class LC_JZ05 {
    public static void main(String[] args) {
        System.out.println(new Solution().replaceSpace("hello world hello"));
    }

    static class Solution {
        public String replaceSpace(String s) {
            int len = s.length();
            char[] array = new char[len * 3];
            int size = 0;
            for (int i = 0; i < len; i++) {
                char c = s.charAt(i);
                if (c == ' ') {
                    array[size++] = '%';
                    array[size++] = '2';
                    array[size++] = '0';
                } else {
                    array[size++] = c;
                }
            }
            return new String(array, 0, size);
        }
    }
}
